home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earcd / phase5 / ppcrelease / tools / ppcloadtimer.c < prev    next >
C/C++ Source or Header  |  1998-02-21  |  3KB  |  103 lines

  1. /*
  2.  * This program does load an Elf Binary and runs it as a PPC Task.
  3.  * It doesn`t return until the Task completes.
  4.  * It measures the time the PPCRunObject() function
  5.  * needs.
  6.  *
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <devices/timer.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <proto/timer.h>
  14. #include <PowerUP/pragmas/ppc_pragmas.h>
  15. #include <PowerUP/clib/ppc_protos.h>
  16. #include "PPCLoadTimer_VERSION.h"
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19.  
  20. UBYTE vers[] = VERSTAG;
  21.  
  22. extern struct ExecBase    *SysBase;
  23.  
  24. void    main(ULONG    argc,
  25.              char    *argv[])
  26. {
  27. struct Library        *PPCLibBase;
  28. ULONG            Result;
  29. APTR            MyObject;
  30. ULONG            ticks;
  31. ULONG            allticks,secs,mics;
  32. float            micros;
  33. struct MsgPort        *timermp;
  34. struct timerequest    *timerio;
  35. struct EClockVal    MyOldEClockVal;
  36. struct EClockVal    MyEClockVal;
  37. struct Library        *TimerBase;
  38.  
  39.   if((argc < 2L) || (argc >3L))
  40.   {
  41.     printf("Usage: Name [Value]\n");
  42.   }
  43.   else
  44.   {
  45.     if ((timermp = CreatePort(NULL, 0)) != NULL)
  46.     {
  47.       if ((timerio = (struct timerequest*) CreateStdIO(timermp)) != NULL)
  48.       {
  49.         if (OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)timerio, 0) == 0L)
  50.         {
  51.           TimerBase    =    (struct Library*) timerio->tr_node.io_Device;
  52.  
  53.           if (PPCLibBase=OpenLibrary("ppc.library",0))
  54.           {
  55.             if (MyObject=PPCLoadObject(argv[1]))
  56.             {
  57.               ticks=ReadEClock(&MyOldEClockVal);
  58.  
  59.               Result=PPCRunObject(MyObject,
  60.                                   argc ==3 ? (APTR) atoi(argv[2]) : NULL);
  61.  
  62.               ticks=ReadEClock(&MyEClockVal);
  63.  
  64.               if (MyEClockVal.ev_hi <= MyOldEClockVal.ev_hi)
  65.               {
  66.                 allticks=MyEClockVal.ev_lo - MyOldEClockVal.ev_lo;
  67.               }
  68.               else
  69.               {
  70.                 if (MyEClockVal.ev_lo <= MyOldEClockVal.ev_lo)
  71.                 {
  72.                   allticks=MyEClockVal.ev_lo - MyOldEClockVal.ev_lo;
  73.                 }
  74.                 else
  75.                 {
  76.                   allticks=MyOldEClockVal.ev_lo - MyEClockVal.ev_lo;
  77.                 }
  78.                 allticks+=(MyEClockVal.ev_hi - MyOldEClockVal.ev_hi)<<16;
  79.               }
  80.  
  81.               secs    =    allticks/ticks;
  82.               micros    =    ((float) 1/((float) ticks/ (float) ((allticks-(secs*ticks)))))*1000000;
  83.               mics    =    micros;
  84.  
  85.               printf("RunTime: %ld.%06ld secs\n",secs,mics);
  86.               printf(" Result: 0x%lx : %ld\n",Result,Result);
  87.               PPCUnLoadObject(MyObject);
  88.             }
  89.             else
  90.             {
  91.               printf("Can't load %s\n",argv[1]);
  92.             }
  93.             CloseLibrary(PPCLibBase);
  94.           }
  95.           CloseDevice((struct IORequest *)timerio);
  96.         }
  97.         DeleteStdIO((struct IOStdReq *)timerio);
  98.       }
  99.       DeletePort(timermp);
  100.     }
  101.   }
  102. }
  103.